<?php
class keu_transaksi_detail_model extends MY_Model {
	var $model = 'keu_transaksi_detail';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	TD.*, COA.NAMA_COA, CC.NAMA_COST_CENTER
					FROM	KEU_TRANSAKSI_DETAIL TD
							LEFT JOIN KEU_COA COA ON COA.ID_COA = TD.ID_COA
							LEFT JOIN SW_COST_CENTER CC ON TD.KD_COST_CENTER = CC.ID_COST_CENTER_PK
					WHERE	
							TD.ID_DOK = '".post('id_dok')."'
							AND (NVL(TD.DEBET, 0)> 0 or NVL(TD.KREDIT, 0)> 0)
					ORDER BY ".(post('sort')=='' ? 'NVL(TD.DEBET,0) DESC, TD.ID_COA' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('KEU_TRANSAKSI_DETAIL', $arr_data);
	}
	
	function Update($arr_data, $arr_new_data){
		$this->db->update('KEU_TRANSAKSI_DETAIL', $arr_data, $arr_new_data);
	}
	
	
	function DeleteSingle($as_id_doc, $as_cost_center, $as_coa_code)
	{
		try {
			$this->db->delete('KEU_TRANSAKSI_DETAIL', array('id_dok' => $as_id_doc, 
														'KD_COST_CENTER' => $as_cost_center,
														'id_coa' => $as_coa_code));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>